/**
 * 系统管理  角色管理
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>角色管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">

      <el-form-item label="搜索：">
        <el-input size="small" v-model="formInline.roleName" placeholder="输入角色名称"></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-input size="small" v-model="formInline.roleNo" placeholder="输入角色代码"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
        <el-button size="small" type="primary" icon="el-icon-plus" @click="handleEdit()">添加</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" type="selection" width="60">
      </el-table-column>
      <el-table-column sortable prop="roleName" label="角色名称" width="300">
      </el-table-column>
      <el-table-column sortable prop="roleNo" label="角色代码" width="300">
      </el-table-column>
      <el-table-column sortable prop="editTime" label="修改时间" width="300">
        <template slot-scope="scope">
          <div>{{scope.row.editTime|timestampToTime}}</div>
        </template>
      </el-table-column>
      <el-table-column sortable prop="editUser" label="修改人" width="300">
      </el-table-column>
      <el-table-column align="center" label="操作" min-width="300">
        <template slot-scope="scope">
          <el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button size="small" type="danger" @click="deleteUser(scope.$index, scope.row)">删除</el-button>
          <el-button size="small" type="success" @click="menuAccess(scope.$index, scope.row)">菜单权限</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
    <!-- 编辑界面 -->
    <el-dialog :title="title" :visible.sync="editFormVisible" width="30%" @click='closeDialog("edit")'>
      <el-form label-width="120px" :model="editForm" ref="editForm" :rules="rules">
        <el-form-item label="系统编码" prop="systemNo">
          <el-input size="small" v-model="editForm.systemNo" auto-complete="off" placeholder="请输入系统编码"></el-input>
        </el-form-item>
        <el-form-item label="角色名称" prop="roleName">
          <el-input size="small" v-model="editForm.roleName" auto-complete="off" placeholder="请输入角色名称"></el-input>
        </el-form-item>
        <el-form-item label="角色代码" prop="roleNo">
          <el-input size="small" v-model="editForm.roleNo" auto-complete="off" placeholder="请输入角色代码"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click='closeDialog("edit")'>取消</el-button>
        <el-button size="small" type="primary" :loading="loading" class="title" @click="submitForm('editForm')">保存</el-button>
      </div>
    </el-dialog>
    <!-- 菜单权限 -->
    <el-dialog title="菜单权限" :visible.sync="menuAccessshow" width="30%" @click='closeDialog("perm")'>
      <el-tree ref="tree" default-expand-all="" :data="RoleRight" :props="RoleRightProps" :default-checked-keys="checkmenu" node-key="id" show-checkbox>
      </el-tree>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click='closeDialog("perm")'>取消</el-button>
        <el-button size="small" type="primary" :loading="loading" class="title" @click="menuPermSave">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script setup>
import {onMounted, ref} from "vue";
const nshow = ref(true); // switch开启
const fshow = ref(false); // switch关闭
const loading = ref(false); // 是显示加载
const editFormVisible = ref(false); // 控制编辑页面显示与隐藏
const menuAccessshow = ref(false); // 控制数据权限显示与隐藏
const title = ref('添加');
const editForm = ref({
  roleId: '',
  systemNo: '',
  roleNo: '',
  roleName: '',
  token: localStorage.getItem('logintoken')
});

// rules 表单验证
const rules = ref({
  systemNo: [
    { required: true, message: '请输入系统编码', trigger: 'blur' }
  ],
  roleNo: [
    { required: true, message: '请输入角色代码', trigger: 'blur' }
  ],
  roleName: [
    { required: true, message: '请输入角色名称', trigger: 'blur' }
  ]
});

const formInline = ref({
  page: 1,
  limit: 10,
  varLable: '',
  varName: '',
  token: localStorage.getItem('logintoken')
});

// 删除
const seletedata = ref({
  ids: '',
  token: localStorage.getItem('logintoken')
});

const userparm = ref([]); // 搜索权限
const listData = ref([]); // 用户数据

// 数据权限
const RoleRight = ref([]);
const RoleRightProps = ref({
  children: 'children',
  label: 'name'
});

// 选中
const checkmenu = ref([]);
// 参数role
const saveroleId = ref('');

// 分页参数
const pageparm = ref({
  currentPage: 1,
  pageSize: 10,
  total: 10
});

// 获取角色列表
const getdata = (parameter) => {
  // 模拟数据
  const res = {
    code: 0,
    msg: null,
    count: 6,
    data: []
  };
  loading.value = false;
  listData.value = res.data;
  // 分页赋值
  pageparm.value.currentPage = formInline.value.page;
  pageparm.value.pageSize = formInline.value.limit;
  pageparm.value.total = res.count;
};

// 创建时调用
onMounted(() => {
  getdata(formInline.value);
});
</script>


<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>

 